package com.uno.mapsearch.rest;

import java.io.IOException;
import java.util.ArrayList;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBElement;

import com.uno.mapsearch.dao.SampleDao;
import com.uno.mapsearch.model.Sample;

@Path("/samples")
public class SampleRestService {

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public SampleSearchResult getSamples() {
		return new SampleSearchResult(new ArrayList<Sample>(SampleDao.instance.getModel().values()));
	}

	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	public Sample newSample(JAXBElement<Sample> newSampleElement) throws IOException {
		Sample newSample = newSampleElement.getValue();		
		Sample result = SampleDao.instance.addSample(newSample);
		return result;
	}

}
